package cloud.estate.owner.service.impl;

import cloud.estate.commons.bean.Owner;
import cloud.estate.commons.handler.exception.*;
import cloud.estate.commons.mapper.OwnerMapper;
import cloud.estate.commons.util.JsonResult;
import cloud.estate.commons.util.ResultTool;
import cloud.estate.owner.service.ownerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class ownerServiceImpl extends ServiceImpl<OwnerMapper, Owner> implements ownerService {
    @Override
    public JsonResult addOneOwner(Owner owner){
        try {
            boolean save = save(owner);
            if (save){
                return  ResultTool.success("添加成功");
            }
            return ResultTool.fail(501,"添加失败");
        } catch (Exception e) {
            throw new AddOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult deleteOneOwner(String id){
        try {
            return super.removeById(id) ? ResultTool.success("删除成功") : ResultTool.fail(502,"删除失败");
        } catch (Exception e) {
            throw new DealOneByIdException(e.getMessage());
        }
    }
    @Override
    public JsonResult updateOneOwner(Owner owner){
        try {
            return updateById(owner) ? ResultTool.success("更新成功") : ResultTool.fail(503,"更新失败");
        } catch (Exception e) {
            throw new UpdateOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult getOneOwner(String id){
        try {
            return ResultTool.success(getById(id));
        } catch (Exception e) {
            throw new FindOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult listAllOwner(){
        try {
            return ResultTool.success(list());
        } catch (Exception e) {
            throw new FindAllException(e.getMessage());
        }
    }
}
